package com.csi.jf.crucible.pro.controller;

import java.util.List;

import com.chinasofti.ro.bizframework.core.json.jsonlib.processor.TimestampJsonValueProcessor;
import com.chinasofti.ro.bizframework.core.mvc.Controller;
import com.chinasofti.ro.bizframework.core.mvc.View;
import com.chinasofti.ro.bizframework.modules.json.JSONArray;
import com.chinasofti.ro.bizframework.modules.json.JsonConfig;
import com.csi.jf.crucible.common.util.LoginUtils;
import com.csi.jf.crucible.pro.service.WorkbenchService;
import com.csi.jf.crucible.ptservice.model.PTSTask;
import com.csi.jf.crucible.ptservice.model.ServiceOrders;
import com.csi.jf.crucible.ptservice.service.ServiceOrdersService;

/**
 * <p>controller</p>
 * 
 * @author BizFoundation
 * @version 1.0
 * @since 1.0
 */
public class WorkbenchController extends Controller {
    /**
     * <p>显示列表</p>
     * 
     */
    public void showIndex() {
        View view = new View(SUCCESS);
        Long jfID=null;
        if(null!=LoginUtils.getLoginUser()){
        	jfID=LoginUtils.getLoginUser().getJfid();
        }
        List<PTSTask>  tasklist = workbenchService.findTaskByJfID(jfID);
		JsonConfig config = new JsonConfig();
	    config.registerJsonValueProcessor(java.sql.Timestamp.class,new TimestampJsonValueProcessor());
	    String serviceTaskList = JSONArray.fromObject(tasklist, config).toString();
	    view.bind("serviceTaskList",serviceTaskList);
        this.render(view);
    }
	/**
	 * <p>显示列表</p>
	 * 
	 */
	public void showWorkbench(String proID,String status,Long taskId) {
	    View view = new View(SUCCESS);
	    ServiceOrders serviceOrders = (ServiceOrders)serviceOrdersService.findByTaskId(taskId);
	    String reviewId = serviceOrders == null ? "" : serviceOrders.getReviewId();
	    
	    view.bind("proID",proID);
	    view.bind("status",status);
	    view.bind("taskId",taskId);
	    view.bind("reviewId",reviewId);
        this.render(view);
	}
	/**
     * <p>显示列表</p>
     * 
     */
    public void showWorkbenchPost() {
        View view = new View(SUCCESS);
        this.render(view);
    }
	/**
     * <p>显示task列表</p>
     * 
     */
    public void findTaskByJfID(Long JfID) {
    	List<PTSTask>  tasklist = workbenchService.findTaskByJfID(JfID);
		JsonConfig config = new JsonConfig();
	    config.registerJsonValueProcessor(java.sql.Timestamp.class,new TimestampJsonValueProcessor());
	    String json = JSONArray.fromObject(tasklist, config).toString();
		this.renderJSON(json);
    }
	/**
     * <p>专家任务操作，包括接受、拒绝、确认收款</p>
     * 
     */
    public void operateTask(String type,String taskId) {
    	workbenchService.operateTask(type, taskId);
	    View view = new View(SUCCESS);
        this.render(view);
    }
    
    /**
     * 根据revviewid更新review状态
     */
    void updateReviewStatus(Long taskId,String status) {
    	
    	ServiceOrders ptsService=(ServiceOrders) serviceOrdersService.findByTaskId(taskId);
    	if(null!=ptsService){
    		workbenchService.updateReviewStatus(ptsService.getReviewId(), status);
    	}
    }
    
    /**
     * <p>注入 WorkbenchService</p>
     */
    private WorkbenchService workbenchService;

	public void setWorkbenchService(WorkbenchService workbenchService) {
		this.workbenchService = workbenchService;
	}
	
    /**
     * <p>注入 pTSserviceService</p>
     */
    private ServiceOrdersService serviceOrdersService;
    
	public void setServiceOrdersService(ServiceOrdersService serviceOrdersService) {
		this.serviceOrdersService = serviceOrdersService;
	}
	
}